package com.purong.purong.widget;

import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.makeramen.roundedimageview.RoundedImageView;


/**
 * Created by Pan_ on 2015/2/2.
 */
public class RadiusImageView extends RoundedImageView {
    private String url;
    private boolean isAttachedToWindow;
    private boolean isClickDark;
    public RadiusImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RadiusImageView(Context context) {
        super(context);
    }

    public void setClickDark(boolean isClickDark){
        this.isClickDark=isClickDark;
    }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (isClickDark){
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    Drawable drawable=getDrawable();
                    if(drawable!=null) {
                        drawable.mutate().setColorFilter(Color.GRAY,
                                PorterDuff.Mode.MULTIPLY);
                    }
                    break;
                case MotionEvent.ACTION_MOVE:
                    break;
                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_UP:
                    Drawable drawableUp=getDrawable();
                    if(drawableUp!=null) {
                        drawableUp.mutate().clearColorFilter();
                    }
                    break;
            }
        }


        return super.onTouchEvent(event);
    }

//    @Override
//    public void onAttachedToWindow() {
//        isAttachedToWindow = true;
//        setImageUrl(url);
//        super.onAttachedToWindow();
//    }
//
//    @Override
//    public void onDetachedFromWindow() {
//        Picasso.with(getContext()).cancelRequest(this);
//        isAttachedToWindow = false;
//        setImageBitmap(null);
//        super.onDetachedFromWindow();
//    }
//
//
//    public void setImageUrl(NineGridlayout layou,String url) {
//        if (!TextUtils.isEmpty(url)) {
//            this.url = url;
//            if (isAttachedToWindow) {
//                Picasso.with(getContext()).loadFile(url).placeholder(new ColorDrawable(Color.parseColor("#f5f5f5"))).into(this);
//            }
//        }
//    }
}
